package com.ai.microservice01.controller;

import com.ai.common.api.EurekaOldApi;
import com.ai.common.vo.UserVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: EurekaOldController
 * @Description: user控制层
 * @author: sxs
 * @date: 2021/6/30 下午3:54
 * @Version: 0.0.1
 */
@RestController
@RequestMapping("/serviced")
//跨域注解
@CrossOrigin
@Api(tags = "用户接口")
public class EurekaOldController {

    @Autowired(required = false)
    private EurekaOldApi eurekaOldApi;

    /**
     * 根据id查询单个用户
     *
     * @param id
     * @return byId 单条用户数据
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "查询单个用户信息")
    public String test(@PathVariable("id") String id) {
        String byId = eurekaOldApi.findById(id);
        return byId;
    }

    /**
     * 添加用户
     *
     * @param userVo 用户信息
     * @return true/false
     */
    @ApiOperation(value = "添加用户")
    @PostMapping("/add")
    public boolean add(@RequestBody UserVo userVo) {
        System.out.println(userVo);
        boolean save = eurekaOldApi.add(userVo);
        return save;
    }

    /**
     * 查询所有用户
     *
     * @return List<UserVo> 用户集合
     */
    @ApiOperation(value = "查询所有用户")
    @GetMapping("/findAll/{current}/{limit}")
    public Page<UserVo> findAll(@PathVariable Long current, @PathVariable Long limit) {
        return eurekaOldApi.findAll(current, limit);
    }

    /**
     * 删除用户
     *
     * @param id 用户id
     * @return true/false
     */
    @ApiOperation(value = "删除用户")
    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable("id") String id) {
        return eurekaOldApi.delete(id);
    }

    /**
     * 更新用户信息
     *
     * @param userVo 用户信息
     * @return true/false
     */
    @ApiOperation(value = "更新用户信息")
    @PostMapping("/update")
    public boolean update(@RequestBody UserVo userVo) {
        return eurekaOldApi.update(userVo);
    }

}
